package com.learn.step03_functions

/**
 *
 *
 * @author: hbliy
 * @date: 2025/7/9 14:15
 */

fun main(args: Array<String>) {
    val number = (Math.random() * 50).toInt() + 1
    println(formatInebriationStatus(castFireball(10)))
    println(formatInebriationStatus(castFireball(20)))
    println(formatInebriationStatus(castFireball(30)))
    println(formatInebriationStatus(castFireball(40)))
    println(formatInebriationStatus(castFireball(50)))
}

private fun formatInebriationStatus(inebriationLevel: Int) = when (inebriationLevel) {
    in 1..10 -> "tipsy（微醺）"
    in 11..20 -> "sloshed（微醉）"
    in 21..30 -> "soused（醉了）"
    in 31..40 -> "stewed（大醉）"
    in 41..50 -> "..t0aSt3d（烂醉如泥）"
    else -> "WHAT!"
}


private fun castFireball(numFireballs: Int = 2): Int {
    println("A glass of Fireball springs into existence. (x$numFireballs)")
//    return (Math.random() * 50 + 1).toInt();

//    使用(1..50).random()生成基础随机值 (1-50)
//    通过minOf(numFireballs, 5)限制最大乘数为 5（避免过量饮酒导致数值溢出）
//    乘以酒的数量并除以 5，使醉酒程度与饮酒量成比例
    return (1..50).random() * minOf(numFireballs, 5) / 5
}